<?php
class Crumb
{
    CONST SALT = "b8e7ae1251dfh3hsd8w2e463a7f086122cf37e4f7";
    static private $ttl = 3600;
    static public function challenge ($data)
    {
        return hash_hmac('md5', $data, self::SALT);
    }
    static public function issueCrumb ($uid, $action = -1)
    {
        $i = ceil(time() / self::$ttl);
        return substr(self::challenge($i . $action . $uid), - 12, 10);
    }
    static public function verifyCrumb ($uid, $crumb, $action = -1)
    {
        $i = ceil(time() / self::$ttl);
        if (substr(self::challenge($i . $action . $uid), - 12, 10) == $crumb || substr(self::challenge(($i - 1) . $action . $uid), - 12, 10) == $crumb)
            return true;
        return false;
    }
}
?>